package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.CategoryVo;
import com.spzx.product.domain.Category;
import com.spzx.product.mapper.CategoryMapper;
import com.spzx.product.service.ICategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "商品分类接口管理")
@RestController
@RequestMapping("/category")
public class CategoryController extends BaseController {

    @Autowired
    private ICategoryService categoryService;

    @Autowired
    private CategoryMapper categoryMapper;

    @Operation(summary = "获取分类下拉树列表")
    @GetMapping(value = "/treeSelect/{id}")
    public AjaxResult treeSelect(@PathVariable Long id) {
        // 思路，获取下拉列表，所以返回的集合，具体是什么集合就有点懵逼，怎么分类的自己也暂时想不到
      List<Category> categoryList =  categoryService.treeSelect(id);
        return success(categoryList);
    }


    @PostMapping("/export")
    public void export(HttpServletResponse response){
        // 导出功能，不能用 return
        categoryService.exportData(response);
    }

    @PostMapping("/import")
    public AjaxResult importFile(@RequestParam("file") MultipartFile multipartFile){
      //  System.out.println("导入过程");
        categoryService.importFile(multipartFile);
        return success();
    }



    @InnerAuth
    @GetMapping(value = "/getOneCategory")
    public R<List<CategoryVo> > getOneCategory() {

       List<CategoryVo>  categoryVoList =  categoryService.getOneCategory();

        return R.ok(categoryVoList);
    }

    @InnerAuth
    @GetMapping(value = "/tree")
    public R<List<CategoryVo> > tree() {

        List<CategoryVo>  categoryVoList =  categoryService.tree();

        return R.ok(categoryVoList);
    }




}